package ac2;

import net.tinyos.util.Dump;
import ac2.util.serial.packets.*;
import ac2.util.serial.*;

public class SenderInterface
{
    public static void main(String[] args)
    {
        if (args.length == 4)
        {
            runCommand(args[0], args[1], args[2], args[3]);
            System.exit(0);
        }
        else
        {
            printUsage();
            System.exit(1);
        }
    }

    private static void runCommand(String mote, String command, String argument, String nodeId)
    {
    	//if (System.getenv("MOTECOM") == null)
    	//{
    	//	System.out.println("ERROR! MOTECOM environment variable not set.\n" +
    	//		"Set using 'setMoteCom' command.");
    	//	System.exit(1);
    	//}
    	
    	System.out.println(
            "Command: " + command + "\n" +
            "Argument: " + argument + "\n" +
            "Node ID: " + nodeId + "\n" +
            "Target Mote: " + mote);
            //"Target Mote: " + System.getenv("MOTECOM"));
    	
    	IBytePacket packet = PacketFactory.Create(command, argument, nodeId);
    	if (packet != null)
    	{
    		PacketSender.send(packet, mote);
    	}
    	else
    	{
    		System.out.println("Error creating packet");
    	}
    }

    private static void printUsage()
    {
        System.out.println("Usage:");
        System.out.println("    java -jar PacketListener.jar <mote address> <command> <argument> <node_id>");
        System.out.println("    Commands are:");
        System.out.println("        UPDATE_TEMP <temp in F> <target zone>");
        System.out.println("        REQUEST_ZONE_STATUS 0 <target zone>");
        System.out.println("        SET_MODE <mode> <target zone>");
    }

}
